home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / iritsm3s.zip / CAGDMESH.C < prev    next >
C/C++ Source or Header  |  1991-05-18  |  2KB  |  70 lines

  1. /******************************************************************************
  2. * CagdMesh.c - Extract surface control mesh/curve control polygon as polyline *
  3. *******************************************************************************
  4. * Written by Gershon Elber, Aug. 90.                          *
  5. ******************************************************************************/
  6.  
  7. #include "cagd_loc.h"
  8.  
  9. /******************************************************************************
  10. * Extract the control polygon of a curve as a polyline.                  *
  11. ******************************************************************************/
  12. CagdPolylineStruct *CagdCrv2CtrlPoly(CagdCrvStruct *Crv)
  13. {
  14.     int i,
  15.     Length = Crv->Length;
  16.     CagdRType **CrvP = Crv -> Points;
  17.     CagdPtStruct *NewPolyline;
  18.     CagdPolylineStruct *P;
  19.  
  20.     P = CagdPolylineNew(Length);
  21.     NewPolyline = P -> Polyline;
  22.  
  23.     for (i = 0; i < Length; i++) {
  24.     CagdCoerceToE3(NewPolyline -> Pt, CrvP, i, Crv -> PType);
  25.     NewPolyline++;
  26.     }
  27.     return P;
  28. }
  29.  
  30. /******************************************************************************
  31. * Extract the control mesh of a surface as a list of polylines.              *
  32. ******************************************************************************/
  33. CagdPolylineStruct *CagdSrf2CtrlMesh(CagdSrfStruct *Srf)
  34. {
  35.     int i, j, SrfIndex,
  36.     ULength = Srf->ULength,
  37.     VLength = Srf->VLength;
  38.     CagdRType **SrfP = Srf -> Points;
  39.     CagdPtStruct *NewPolyline;
  40.     CagdPolylineStruct *P, *PList = NULL;
  41.  
  42.     for (j = 0; j < VLength; j++) {       /* Generate the rows of the mesh. */
  43.     P = CagdPolylineNew(ULength);
  44.     NewPolyline = P -> Polyline;
  45.  
  46.     SrfIndex = CAGD_MESH_UV(Srf, 0, j); /* Start at the begining of row. */
  47.     for (i = 0; i < ULength; i++) {
  48.         CagdCoerceToE3(NewPolyline -> Pt, SrfP, SrfIndex, Srf -> PType);
  49.             NewPolyline++;
  50.         SrfIndex += CAGD_NEXT_U(Srf);
  51.     }
  52.     CAGD_LIST_PUSH(P, PList);
  53.     }
  54.  
  55.     for (i = 0; i < ULength; i++) {       /* Generate the cols of the mesh. */
  56.     P = CagdPolylineNew(VLength);
  57.     NewPolyline = P -> Polyline;
  58.  
  59.     SrfIndex = CAGD_MESH_UV(Srf, i, 0); /* Start at the begining of row. */
  60.     for (j = 0; j < VLength; j++) {
  61.         CagdCoerceToE3(NewPolyline -> Pt, SrfP, SrfIndex, Srf -> PType);
  62.             NewPolyline++;
  63.         SrfIndex += CAGD_NEXT_V(Srf);
  64.     }
  65.     CAGD_LIST_PUSH(P, PList);
  66.     }
  67.  
  68.     return PList;
  69. }
  70.